home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / mquery / mgrid.frm < prev    next >
Text File  |  1995-05-02  |  19KB  |  737 lines

  1. VERSION 2.00
  2. Begin Form fGridFrm 
  3.    BackColor       =   &H00C0C0C0&
  4.    ClientHeight    =   3135
  5.    ClientLeft      =   1455
  6.    ClientTop       =   2640
  7.    ClientWidth     =   6675
  8.    ClipControls    =   0   'False
  9.    Height          =   3540
  10.    Icon            =   MGRID.FRX:0000
  11.    Left            =   1395
  12.    LinkTopic       =   "Form1"
  13.    ScaleHeight     =   3125.913
  14.    ScaleMode       =   0  'User
  15.    ScaleWidth      =   6692.959
  16.    Tag             =   "Dynaset"
  17.    Top             =   2295
  18.    Width           =   6795
  19.    Begin Grid cGrid 
  20.       Height          =   2715
  21.       Left            =   0
  22.       TabIndex        =   9
  23.       Top             =   420
  24.       Width           =   6675
  25.    End
  26.    Begin PictureBox ViewButtons 
  27.       BackColor       =   &H00C0C0C0&
  28.       BorderStyle     =   0  'None
  29.       Height          =   375
  30.       Left            =   0
  31.       ScaleHeight     =   372
  32.       ScaleMode       =   0  'User
  33.       ScaleWidth      =   5171.607
  34.       TabIndex        =   0
  35.       Top             =   24
  36.       Width           =   5175
  37.       Begin CommandButton SortButton 
  38.          Caption         =   "&Sort"
  39.          Height          =   372
  40.          Left            =   3720
  41.          TabIndex        =   8
  42.          Top             =   0
  43.          Width           =   612
  44.       End
  45.       Begin CommandButton FilterButton 
  46.          Caption         =   "Fil&ter"
  47.          Height          =   372
  48.          Left            =   3120
  49.          TabIndex        =   7
  50.          Top             =   0
  51.          Width           =   612
  52.       End
  53.       Begin CommandButton RefreshButton 
  54.          Caption         =   "&Redo"
  55.          Height          =   372
  56.          Left            =   2520
  57.          TabIndex        =   6
  58.          Top             =   0
  59.          Width           =   612
  60.       End
  61.       Begin CommandButton CloseButton 
  62.          Cancel          =   -1  'True
  63.          Caption         =   "&Close"
  64.          Height          =   372
  65.          Left            =   4320
  66.          TabIndex        =   5
  67.          Top             =   0
  68.          Width           =   612
  69.       End
  70.       Begin CommandButton MoreButton 
  71.          Caption         =   "&More"
  72.          Height          =   372
  73.          Left            =   1320
  74.          TabIndex        =   4
  75.          Top             =   0
  76.          Width           =   612
  77.       End
  78.       Begin CommandButton NextButton 
  79.          Caption         =   "&Next"
  80.          Height          =   372
  81.          Left            =   120
  82.          TabIndex        =   3
  83.          Top             =   0
  84.          Width           =   612
  85.       End
  86.       Begin CommandButton FirstButton 
  87.          Caption         =   "&First"
  88.          Height          =   372
  89.          Left            =   720
  90.          TabIndex        =   2
  91.          Top             =   0
  92.          Width           =   612
  93.       End
  94.       Begin CommandButton FindButton 
  95.          Caption         =   "F&ind"
  96.          Height          =   372
  97.          Left            =   1920
  98.          TabIndex        =   1
  99.          Top             =   0
  100.          Width           =   612
  101.       End
  102.    End
  103. End
  104.  
  105. Option Explicit
  106.  
  107. 'form variables
  108. 'Dim FDS As dynaset         'current form's dynaset
  109. Dim FDS As snapshot        'current form's snapshot
  110. Dim FDynSt As String       'dynaset open string
  111. Dim FTblname As String     'form dynaset table name
  112. Dim FCurrentRow As Long    'current row in dynaset
  113. Dim FGridRow As Integer    'current grid row
  114. Dim FNotFound As Integer   'find not found flag
  115. Dim FFindForm As New fFind 'find form
  116. Dim FNumbRows As Long      'total number of rows in table
  117. Dim FDynaString As String  'dynaset open string
  118.  
  119. Sub cGrid_DblClick ()
  120.   Dim r As Integer       'return from execute sql
  121.   Dim fn As String       'field name
  122.  
  123.   On Error GoTo ZoomErr
  124.   r = cGrid.Row
  125.   cGrid.Row = 0
  126.   'get field name
  127.   fn = cGrid.Text
  128.   cGrid.Row = r
  129.  
  130.   'make sure it's a string or memo field
  131.   'If FDS(fn).Type = FT_STRING Or FDS(fn).Type = FT_MEMO Then
  132.     ' gstZoomData = cGrid.Text
  133.     ' fZoom.Caption = fn
  134.     ' fZoom.Top = Top + 1200
  135.     ' fZoom.Left = Left + 250
  136.     ' fZoom.CloseZoomButton.Visible = True
  137.      'fZoom.Show MODAL
  138.   'End If
  139.   GoTo ZoomEnd
  140.  
  141. ZoomErr:
  142.   ShowError
  143.   Resume ZoomEnd
  144.  
  145. ZoomEnd:
  146.  
  147. End Sub
  148.  
  149. Sub cGrid_KeyUp (KeyCode As Integer, Shift As Integer)
  150.   'zoom on F4 key press
  151.   If KeyCode = &H73 Then   'F4
  152.     cGrid_DblClick
  153.   End If
  154. End Sub
  155.  
  156. Sub CloseButton_Click ()
  157.   If Not gStoredFlag Then ' this query did not come from storage
  158.     fQuery.RunSaveQryButton.Caption = "&Store Query "
  159.     fQuery.RunSaveQryButton.Enabled = True
  160.     fQuery.RunQueryButton.Enabled = False
  161.     Else
  162.     fQuery.RunSaveQryButton.Caption = "&Load Query"
  163.     fQuery.RunSaveQryButton.Enabled = False
  164.     fQuery.RunQueryButton.Enabled = False
  165.     'gStoredFlag = False
  166.   End If
  167.  
  168.   fQuery.Show
  169.   Unload Me
  170. End Sub
  171.  
  172. Sub FilterButton_Click ()
  173.   On Error GoTo FilterErr
  174.  
  175. '  Dim ds1 As dynaset, ds2 As dynaset
  176.   Dim ds1 As snapshot, ds2 As snapshot
  177.   'Dim gFilterStr As String
  178.   Dim numbrows As Long    'local number of rows
  179.  
  180.   Set ds1 = FDS            'save the dynaset
  181.    Dim i As Integer, r As Integer, c As Integer
  182.  
  183.    'On Error GoTo FindErr
  184.  
  185.    'load the column names into the filter form
  186.    'the 1st time it is loaded
  187.      fFilter.cExpr.Text = ""
  188.      fFilter.cFieldList.Clear
  189.      r = cGrid.Row
  190.      c = cGrid.Col
  191.      cGrid.Row = 0
  192.      cGrid.Col = 0
  193.      For i = 1 To cGrid.Cols - 1
  194.        cGrid.Col = cGrid.Col + 1
  195.        fFilter.cFieldList.AddItem cGrid.Text
  196.      Next
  197.      cGrid.Row = r
  198.      cGrid.Col = c
  199.    
  200.  
  201.    MsgBar "Enter Search Parameters without quotes", False
  202.  
  203.   fFilter.Show MODAL
  204.  
  205.   'gFilterStr = InputBox("Enter Filter Expression:")
  206.   If gFilterStr = "" Then Exit Sub
  207.   
  208.   FDS.Filter = gFilterStr
  209. '  Set ds2 = FDS.CreateDynaset()            'establish the filter
  210.   Set ds2 = FDS.CreateSnapshot()            'establish the filter
  211.   Set FDS = ds2            'assign back to original dynaset object
  212.  
  213.   'everything must be okay so redisplay form on 1st record
  214.   FNumbRows = GetNumbRecsSS(FDS)          'query numb of recs
  215.    If FNumbRows = -1 Then
  216.      'error occurred but go on anyway
  217.      'because row count is non-critical
  218.      Caption = "Dynaset: " + FTblname
  219.      numbrows = gwMaxGridRows
  220.      FCurrentRow = numbrows
  221.    ElseIf FNumbRows = 0 Then
  222.      Beep
  223.      MsgBox "No Records found!", 48
  224.      ResetMouse Me
  225.      Unload Me
  226.      fQuery.Show
  227.      Exit Sub
  228.    ElseIf FNumbRows > gwMaxGridRows Then
  229.      Caption = "Dynaset: " + FTblname + " [" + CStr(FNumbRows) + " total rows]"
  230.      numbrows = gwMaxGridRows
  231.      FCurrentRow = numbrows
  232.    Else
  233.      numbrows = FNumbRows
  234.      Caption = "Dynaset: " + FTblname + " [" + CStr(FNumbRows) + " rows]"
  235.    End If
  236.   If LoadGrid(cGrid, FDS, FDynSt, numbrows, 0) = False Then
  237.     Unload Me
  238.     fQuery.Show
  239.     Exit Sub
  240.   End If
  241.   GoTo FilterEnd
  242.  
  243. FilterErr:
  244.   ShowError
  245.   Set FDS = ds1            're-assign back to original
  246.   Resume FilterEnd
  247.  
  248. FilterEnd:
  249.  
  250. End Sub
  251.  
  252. Sub FindButton_Click ()
  253.    Dim i As Integer, r As Integer, c As Integer
  254.  
  255.    On Error GoTo FindErr
  256.  
  257.    'load the column names into the find form
  258.    'the 1st time it is loaded
  259.    If FFindForm.cFieldList.ListCount = 0 Then
  260.      FFindForm.cFieldList.Clear
  261.      r = cGrid.Row
  262.      c = cGrid.Col
  263.      cGrid.Row = 0
  264.      cGrid.Col = 0
  265.      For i = 1 To cGrid.Cols - 1
  266.        cGrid.Col = cGrid.Col + 1
  267.        FFindForm.cFieldList.AddItem cGrid.Text
  268.      Next
  269.      cGrid.Row = r
  270.      cGrid.Col = c
  271.    End If
  272.  
  273. FindStart:       'used to loop around on not found
  274.  
  275.    'reset the flags
  276.    gfFindFailed = False
  277.    gfFromTableView = True
  278.  
  279.    MsgBar "Enter Search Parameters", False
  280.  
  281.    FFindForm.Show MODAL
  282.   
  283.    MsgBar "Searching for record", True
  284.  
  285.    If gfFindFailed = True Then Exit Sub
  286.  
  287.    FNotFound = False
  288.  
  289.    SetHourGlass Me
  290.  
  291.    'search for the record
  292.    cGrid.SetFocus        'start at the top
  293.    SendKeys "^{Home}"
  294.    cGrid.Col = 1
  295.    cGrid.Row = 0
  296.    'move the right column
  297.    While cGrid.Text <>